<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>改变当前的 umask</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.umask" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">umask</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">umask</span> &mdash; <span class="dc-title">改变当前的 umask</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.umask-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>umask</strong></span>
    ([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$mask</code></span>
  ] ) : <span class="type">int</span></div>

  <p class="para rdfs-comment">
 <span class="function"><strong>umask()</strong></span> 将 PHP 的 umask 设定为
   <code class="parameter">mask</code> &amp; 0777 并返回原来的
   umask。当 PHP 被作为服务器模块使用时，在每个请求结束后 umask
   会被恢复。
  </p>
 </div>

 
  <div class="refsect1 parameters" id="refsect1-function.umask-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">mask</code></dt>

     <dd>

      <p class="para">
       The new umask.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
  <div class="refsect1 returnvalues" id="refsect1-function.umask-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   无参数调用 <span class="function"><strong>umask()</strong></span> 会返回当前的 umask，有参数则返回原来的 umask。
  </p>
 </div>

 
  <div class="refsect1 examples" id="refsect1-function.umask-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2851">
    <p><strong>Example #1 <span class="function"><strong>umask()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$old&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">umask</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">chmod</span><span style="color: #007700">(</span><span style="color: #DD0000">"/path/some_dir/some_file.txt"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0755</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">umask</span><span style="color: #007700">(</span><span style="color: #0000BB">$old</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Checking<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$old&nbsp;</span><span style="color: #007700">!=&nbsp;</span><span style="color: #0000BB">umask</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'An&nbsp;error&nbsp;occured&nbsp;while&nbsp;changing&nbsp;back&nbsp;the&nbsp;umask'</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


  <div class="refsect1 notes" id="refsect1-function.umask-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    在多线程的服务器上尽量避免使用这个函数。创建文件后要改变其权限最好还是使用
    <span class="function"><a href="chmod.html" class="function">chmod()</a></span>。使用 <span class="function"><strong>umask()</strong></span>
    会导致并发程序和服务器发生不可预知的情况，因为它们是使用相同的 umask 的。
   </p>
  </p></blockquote>
 </div>

</div></div></div></body></html>